import { prisma } from "@/lib/prisma"
import { CreateSaleForm } from "@/components/sales/create-sale-form"
import { Metadata } from "next"

export const metadata: Metadata = {
  title: "销售开单 - 商场销售系统",
  description: "销售开单页面",
}

export default async function CreateSalePage() {
  const products = await prisma.product.findMany({
    where: {
      stock: {
        gt: 0 // 只查询有库存的商品
      }
    },
    orderBy: {
      name: 'asc'
    }
  })

  // 序列化商品数据
  const serializedProducts = products.map(product => ({
    ...product,
    price: product.price.toString()
  }))

  return (
    <div className="max-w-4xl mx-auto py-8">
      <div className="bg-white shadow rounded-lg">
        <div className="px-6 py-4 border-b border-gray-200">
          <h1 className="text-xl font-semibold text-gray-900">销售开单</h1>
        </div>
        <CreateSaleForm products={serializedProducts} />
      </div>
    </div>
  )
} 